package com.atguigu.gmall.user.service.impl;

import com.atguigu.gmall.common.util.MD5;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.model.user.UserInfo;
import com.atguigu.gmall.user.mapper.UserAddressMapper;
import com.atguigu.gmall.user.mapper.UserInfoMapper;
import com.atguigu.gmall.user.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: 李旭
 * @Time: 10:17
 * @Description:
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private UserAddressMapper userAddressMapper;

    //校验用户名密码
    @Override
    public UserInfo login(UserInfo userInfo) {
        //1:查询数据库是否有此用户 并且密码还要正确
        return  userInfoMapper.selectOne(new QueryWrapper<UserInfo>()
                .eq("login_name", userInfo.getLoginName())
                .eq("passwd", MD5.encrypt(userInfo.getPasswd())));
    }
    //根据用户ID查询收货地址集合
    @Override
    public List<UserAddress> userAddressList(String userId) {
        return userAddressMapper.selectList(new QueryWrapper<UserAddress>()
          .eq("user_id",userId));
    }

    public static void main(String[] args) {
        System.out.println(MD5.encrypt("123"));
    }



}
